<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'UpdataPassword.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script>
		function checkPwd(){
			var managerName=$("#userName").val();
			var originalpwd=$("#originalPwd").val();
			if(originalpwd==null||originalpwd==""){
				//alert("12121");
				$("#originalPwd").focus();
				$("#message").html("原密码不能为空");
				return "fail";
			}else{
				$.post("CheckPwdAction",{"managerName":managerName,"originalpwd":originalpwd},function(data){
						if(data=="notexist"){
							$("#message").html("原密码错误");
							$("#originalPwd").val("");
							$("#originalPwd").focus();
							return "fail";
						}else if(data=="exist"){
							$("#message").html("");
							return "success";
						}
				});
			}
			
		}
		function submitPwd(){
			var newPwd=$("#newPwd").val();
			var newPwdAgain=$("#newPwdAgain").val();
			var managerName=$("#userName").val();
			 var originalPwd=$("#originalPwd").val();
			if((newPwd==""||newPwd==null)||(originalPwd==""||originalPwd==null)){
				alert("新密码和原密码不能为空");
			}else{
				if(newPwd==newPwdAgain){
					$.post("UpdatePwdAction",{"newPwd":newPwd,"managerName":managerName},function(data){
						if(data="success"){
							alert("修改成功");
							$("#newPwdAgain").val("");
							$("#newPwd").val("");
							$("#originalPwd").val("");
						}else{
							alert("修改失败");
							$("#newPwdAgain").val("");
							$("#newPwd").val("");
							$("#originalPwd").val("");
						}
					});
			}else{
				alert("2次输入密码不一样");
				$("#newPwdAgain").val("");
				$("#newPwdAgain").focus();
			}
			}
			
		}
	</script>
  </head>
  
  <body>
  <div style="position: absolute; left:400px;top: 100px;">
    	原密码：<input type="password" name="originalPwd" id="originalPwd" onblur="checkPwd()"><lable id="message"></lable><br>
    	新密码：<input type="password" name="newPwd" id="newPwd"><br>
    	再输一次：<input type="password" name="newPwdAgain" id="newPwdAgain"><br>
    	<input type="hidden" id="userName" value="${mana.managersName}"><!-- 获取SESSION中的managersName -->
    	<input type="button" value="提交" onclick="submitPwd()">
  </div>
  </body>
</html>
